package com.study.servlet.admin;


import com.alibaba.fastjson.JSON;
import com.study.R;
import com.study.dto.MedalSearchDto;
import com.study.service.MedalSearchService;
import com.study.service.impl.MedalSearchServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackgeName: com.study.servlet.admin
 * @ClassName: CountryListServlet
 * @Author: 严志祥
 * Date: 2022-05-05 12:08
 * project name: web_project_medal
 * @Version:
 * @Description:
 */
@WebServlet("/admin/award-page.let")
public class AwardPageServlet extends HttpServlet {
    private MedalSearchService service = new MedalSearchServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        MedalSearchDto dto = new MedalSearchDto();
        try{
            dto.setCurrent(Integer.valueOf(req.getParameter("current")));
        }catch (Exception e){

        }
        try{
            dto.setMaxRecord(Integer.valueOf(req.getParameter("maxRecord")));
        }catch (Exception e){

        }
        try{
            dto.setSportingId(Integer.valueOf(req.getParameter("sportingId")));
        }catch (Exception e){

        }
        dto.setKey(req.getParameter("key"));


        resp.reset();
        resp.setContentType("application/json;charset=UTF-8");
        try{
            resp.getWriter().print(JSON.toJSON(service.page(dto)));
        }catch (Exception e){
            resp.getWriter().print(JSON.toJSON(R.error().setMessage(e.getMessage())));
            e.printStackTrace();
        }
        resp.flushBuffer();
    }
}
